package com.booklove.domain.po;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;

import com.booklove.constant.JudgeStateConstant;
import com.booklove.constant.WishStateConstant;
import com.booklove.context.BaseContext;
import com.booklove.domain.dto.WishbookDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;

/**
 * <p>
 * 许愿图书
 * </p>
 *
 * @author author
 * @since 2024-09-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("wishbook")
@ApiModel(value="Wishbook对象", description="许愿图书")
public class Wishbook implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "许愿描述")
    private String content;

    @ApiModelProperty(value = "许愿封面")
    private String picture;

    @ApiModelProperty(value = "许愿标题")
    private String title;

    @ApiModelProperty(value = "捐赠地点")
    private Integer addressId;

    @ApiModelProperty(value = "发出许愿的用户id")
    private Integer userId;

    @ApiModelProperty(value = "对应许愿的书籍id")
    private Integer bookId;

    @ApiModelProperty(value = "请求状态-数字字典给出")
    private Integer wishState;

    @ApiModelProperty(value = "审核状态-对应judge种的result")
    private Integer judgeState;

    @ApiModelProperty(value = "创建人")
    private Integer createdBy;

    @ApiModelProperty(value = "创建时间")
    private LocalDateTime createdTime;

    @ApiModelProperty(value = "更新人")
    private Integer updatedBy;

    @ApiModelProperty(value = "更新时间")
    private LocalDateTime updatedTime;

    public static Wishbook createWishBook(WishbookDTO wishbookDTO)
    {
        Wishbook wishbook = new Wishbook();
        BeanUtils.copyProperties(wishbookDTO, wishbook);
        // 用户id
        wishbook.setUserId(BaseContext.getCurrentId().intValue());

        // 将捐献的书籍放置进入待审核状态
        wishbook.setJudgeState(JudgeStateConstant.WAITING_JUDGE);

        // 将捐献的书籍变为等待领取
        wishbook.setWishState(WishStateConstant.WAITING);

        // wish设置时间
        wishbook.setCreatedBy(BaseContext.getCurrentId().intValue());
        wishbook.setCreatedTime(LocalDateTime.now());
        wishbook.setUpdatedBy(BaseContext.getCurrentId().intValue());
        wishbook.setUpdatedTime(LocalDateTime.now());

        return wishbook;
    }


}
